package com.sanyue.dataStructure.Sort;

/**
 * @author sanyue
 * @version 1.0
 * @description: TODO-冒泡排序
 * @date 2022/1/25 下午5:08
 */
public class Bubble<T extends Comparable<T>> extends Sort<T> {
    @Override
    public void sort(T[] nums) {
        int N = nums.length;
        boolean isSorted = false;
        for (int i = N-1; i > 0 && !isSorted; i--) {
            isSorted = true;
            for (int j = 0; j < i; j++) {
                if (less(nums[j+1], nums[j])) {
                    swap(nums, j+1, j);
                    isSorted = false;
                }
            }
        }
    }
}
